<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">车牌号</label>
        <div class="layui-input-block">
            <input type="text" name="card" lay-verify="required" lay-reqtext="车牌号不能为空" placeholder="请输入车牌号" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">车辆品牌</label>
        <div class="layui-input-block">
            <input type="text" name="brand" lay-verify="required" lay-reqtext="品牌不能为空" placeholder="请输入车辆品牌" value="" class="layui-input">
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label required">型号</label>
        <div class="layui-input-block">
            <input type="text" name="type" lay-verify="required" lay-reqtext="型号不能为空" placeholder="请输入型号" value="" class="layui-input">
        </div>
    </div>
    
     <div class="layui-form-item">
        <label class="layui-form-label required">公里数</label>
        <div class="layui-input-block">
            <input type="text" name="type" lay-verify="required" lay-reqtext="公里数不能为空" placeholder="请输入公里数" value="" class="layui-input">
        </div>
    </div>

	<div class="layui-form-item">
	    <label class="layui-form-label">选择车主</label>
	    <div class="layui-input-block">
	      <select name="consumerId" id="consumerSelect" lay-verify="required" lay-search="">
	        <option value=""></option>
	      </select>
	    </div>
	 </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">新增车辆</button>
        </div>
    </div>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
	
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        $.post('/consumer/select',function(res){   
        	$('#consumerSelect').append(" <option value='"+c.id+"'> "+c.name+" </option> "); //给已知标签拼接子标签进去
        	/* for(c of res){
        		if( 当前车主 == c.name){
        			$('#consumerSelect').append(" <option selected value='"+c.id+"'> "+c.name+" </option> "); //给已知标签拼接子标签进去
        		}else{
        			$('#consumerSelect').append(" <option value='"+c.id+"'> "+c.name+" </option> "); //给已知标签拼接子标签进去
        		}
        	} */
        	form.render(); // 当咱们通过jquery、js语法修改了表单的内容、结构的时候  需要让layui的表单进行重写渲染
        })
        
        
        //监听提交
        form.on('submit(saveBtn)', function (data) {
        	data = data.field;
        	layer.alert( JSON.stringify(data) );
        	
        	/* $.post('/consumer/add',data,function(res){
        		if(res){
        			layer.msg('新增成功',{icon:6,time:1000},function(){
        				//刷新父页面    reload() 函数 刷新
        				//window 代表当前页面   window.parent 父页面
        				window.parent.location.reload();
        			});
        		}else{
        			layer.msg('网络延迟~',{icon:5,time:2000});
        		}
        	}) */
            /* var index = layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            }, function () {

                // 关闭弹出层
                layer.close(index);

                var iframeIndex = parent.layer.getFrameIndex(window.name);
                parent.layer.close(iframeIndex);

            }); */

            return false;
        });

    });
</script>
</body>
</html>